package io.github.wppli.config;

import org.apache.spark.SparkContext;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.sql.SparkSession;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SparkConfig {

    @Bean
    public SparkSession sparkSession() {
        return SparkSession.builder()
                .appName("RecommendationSystem")
                .master("local[*]")
//                .master("spark://116.198.239.101:7077")
//                .config("spark.executor.memory", "2g") // 每个执行器分配4G内存
//                .config("spark.executor.cores", "2") // 每个执行器使用1个CPU核心
//                .config("spark.driver.memory", "2g") // 驱动程序分配2G内存
//                .config("master", "local[*]")
                .getOrCreate();
    }

    @Bean
    public JavaSparkContext sparkContext(SparkSession sparkSession) {
        return new JavaSparkContext(sparkSession.sparkContext());
    }
}